package aryn.framework.examples.display;

import aryn.framework.display.MyCanvas;
import aryn.framework.display.MyCanvasLogic;
import aryn.framework.display.MyMouseInfo;
import aryn.framework.display.drawable.Drawable;

public class LogicMouseOver implements MyCanvasLogic {

	private long id1;
	private long id2;
	private long id3;
	MyCanvas canvas;
	MyMouseInfo mouse;
	boolean isCursorChanged = false;
	boolean isClicked = false;
	
	public LogicMouseOver(MyCanvas canvas) throws InterruptedException {
		this.canvas = canvas;
		this.mouse = canvas.getMouseInfo();
		this.id1 = canvas.addString("Mouse: "+ mouse.getMouseX() + "," + mouse.getMouseY(), 0, 40);
		this.id2 = canvas.addString("\"over me\"", 100, 60);
		this.id3 = canvas.addString(" -> i appear", 160, 60);
	}
	
	@Override
	public void update(double dt) {
		canvas.setString(id1, "Mouse: "+ mouse.getMouseX() + "," + mouse.getMouseY());
		Drawable appearString = canvas.getDrawable(id2);
		if (appearString.isMouseOver())
			canvas.getDrawable(id3).setVisible(true);
		else
			canvas.getDrawable(id3).setVisible(false);
		
		Drawable button = canvas.getDrawable(8);
		if (button != null && button.isLeftClicked())
			System.out.println("clicked");
		
//		if (mouse.isPressed()) {
//			isClicked = false;
//		}
//		
//		if (button != null && button.isLeftClicked() && !isClicked) {
//			isClicked = true;
//			if (!isCursorChanged) {
//				canvas.changeCursor(0);
//				isCursorChanged = true;
//			} else {
//				isCursorChanged = false;
//				canvas.changeCursor(1);
//			}
//		}
	}
}
